package com.siwei.mes.service.experiment.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.entity.experiment.ExperimentCheckWaybill;
import com.siwei.mes.mapper.experiment.ExperimentCheckWaybillMapper;
import com.siwei.mes.service.experiment.ExperimentCheckWaybillService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 快检/批检与试验台账和运单的关系(ExperimentCheckWaybill)表服务实现类
 *
 * @author makejava
 * @since 2024-06-01 22:48:07
 */
@Service
public class ExperimentCheckWaybillServiceImpl implements ExperimentCheckWaybillService {
    @Resource
    private ExperimentCheckWaybillMapper experimentCheckWaybillMapper;

    @Override
    public Long create(ExperimentCheckWaybill entity) {
        experimentCheckWaybillMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(ExperimentCheckWaybill entity) {
        ExperimentCheckWaybill experimentCheckWaybill = experimentCheckWaybillMapper.selectByPrimaryKey(entity.getId());
        assertTrue(experimentCheckWaybill == null, "快检/批检与试验台账和运单的关系信息不存在");
        experimentCheckWaybillMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        ExperimentCheckWaybill experimentCheckWaybill = experimentCheckWaybillMapper.selectByPrimaryKey(id);
        assertTrue(experimentCheckWaybill == null, "快检/批检与试验台账和运单的关系信息不存在");
        experimentCheckWaybillMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<ExperimentCheckWaybill> getPage(PageQuery<ExperimentCheckWaybill, ExperimentCheckWaybill> query) {
        ExperimentCheckWaybill searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> experimentCheckWaybillMapper.getList(searchParam));
    }

    @Override
    public ExperimentCheckWaybill loadById(Long id) {
        return experimentCheckWaybillMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ExperimentCheckWaybill> getAll(ExperimentCheckWaybill entity) {
        return experimentCheckWaybillMapper.getList(entity);
    }
}
